package com.atguigu.yygh.hosp.controller.user;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.ScheduleService;
import com.atguigu.yygh.model.hosp.Schedule;
import com.atguigu.yygh.vo.hosp.ScheduleOrderVo;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author luoyin
 * @Date 18:06 2022/10/6
 **/
@RestController
@RequestMapping("/user/schedule")
public class UserScheduleController {

    @Autowired
    private ScheduleService scheduleService;

    @GetMapping("/{pageNum}/{pageSize}/{hoscode}/{depcode}")
    public R getBookingSchedule(@PathVariable Integer pageNum , @PathVariable Integer pageSize,
                                @PathVariable String hoscode , @PathVariable String depcode){
        Map<String,Object> map = scheduleService.selectPage(pageNum,pageSize,hoscode,depcode);
        return R.ok().data(map);
    }

    @GetMapping("/getScheduleDetail/{hoscode}/{depcode}/{workDate}")
    public R getScheduleDetail(@PathVariable String hoscode,
                               @PathVariable String depcode ,
                               @PathVariable String workDate){
        List<Schedule> list = scheduleService.getScheduleDetail(hoscode,depcode,new DateTime(workDate).toDate());
        return R.ok().data("list",list);
    }

    @GetMapping("/getSchedule/{scheduleId}")
    public R getSchedule(@PathVariable String scheduleId){
        Schedule schedule = scheduleService.getSchedule(scheduleId);
        return R.ok().data("schedule",schedule);
    }

    @GetMapping("/scheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable("scheduleId") String scheduleId){
        return scheduleService.getScheduleOrderVo(scheduleId);
    }
}
